var config = require('../../../config');
const gxUrl = config.gxUrl;
const odrallUrl = config.odrallUrl;
const shippUrl = config.shippUrl;

var app=getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    num:1
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

    var that = this;
    app.getUserOpenId(function (err, openid) {
      if(!err){
        wx.request({
          url: odrallUrl+openid, //仅为示例，并非真实的接口地址      
          header: {
            'content-type': 'application/json'
          },
          success: function (res) {
            
            that.setData({
              list: res.data
            })
          }
        });
      }
        
    });

  },
  payinfo: function (e) {
    var id = e.currentTarget.dataset.id;
    var list = this.data.list;
   
    wx.setStorage({
      key: "details",
      data: list[id]
    });
  
    wx.navigateTo({
      url: '/pages/myinfo/order/orderpay/pay',
    })

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    
  },
  
  //确认收货
  shipyes:function(e){
    var that=this;
    var list = that.data.list;
    var idx = e.currentTarget.dataset.idx;
    var url = shippUrl + e.currentTarget.dataset.id;
      wx.request({
        url: url,
        success:function(res){
          list[idx]['orderstatus']=4;
          that.setData({
            list:list
          })
        }
      })
  },
  
  /**
   * 评论跳转
   */
  onpinlun:function(e){
    var idx = e.currentTarget.dataset.idx
    var list = this.data.list;
    var img = list[idx].picture;

    //获取参数
    wx.setStorage({
      key: "img",
      data: gxUrl + img,
    })

    //设置本地缓存
    wx.navigateTo({
      url: '/pages/myinfo/comment/comment?id=' + e.currentTarget.dataset.id + "&proid=" + e.currentTarget.dataset.proid ,
    })

  }

})